package com.java.ui;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class DrawStart extends Thread {
	static Calendar nowTime = Calendar.getInstance();
	static int nowYear = nowTime.get(Calendar.YEAR);
	static int nowMonth = nowTime.get(Calendar.MONTH) + 1;
	static int nowDay = nowTime.get(Calendar.DATE);

	// 判断所选月份的天数，并返回
	public static int getMonthDays(int year, int month) {
		int monthDays = 0;
		if (month == 4 || month == 6 || month == 9 || month == 11) {
			monthDays = 30;
		} else if (month == 2) {
			if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
				monthDays = 29;
			} else
				monthDays = 28;
		} else
			monthDays = 31;
		return monthDays;
	}

	// 返回这个月第一天是星期几
	public static int getFirstWeekDay(int year, int month, int day) {
		nowTime.set(Calendar.YEAR, year);
		nowTime.set(Calendar.MONTH, month);
		nowTime.set(Calendar.DATE, day);
		String date = nowYear + "-" + nowMonth + "-" + nowDay;
		SimpleDateFormat dFormat = new SimpleDateFormat("yyyy-MM-dd");
		Date parse;
		int c = 0;
		try {
			parse = dFormat.parse(date);
			Calendar calendar = new GregorianCalendar();
			calendar.setTime(parse);// 把格式化好的日期对象放进Calendar
			c = calendar.get(Calendar.DAY_OF_WEEK);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		if (c - 1 == 0)
			return 7;
		return c - 1;
	}

	// 线程调用，做到实时显示时间
	public void run() {
		while (true)
			TodoDrawWindow.showNowTime();
	}

	/*public static void main(String[] args) {
		new DrawStart().start();
		new Gui2();
	}*/
}